A “constant pool” is a table or other data structure in which one or more constants, i.e., values that do not change during a relevant time interval, for example during program execution, are stored centrally and from which the value of a constant typically is obtained by associated software code. For example, for each Java class, constants used by methods of the class are stored in a constant table associated with the class, and such methods have and use references to values in the constant table. Certain scripting or other traditionally interpreted programming languages, such as JavaScript, do not natively define a constant pool. Instead, temporary objects or other structures are created dynamically to store constants and other values on which code comprising a script, applet, or other body of code operate.
In some cases, JavaScript or other traditionally interpreted code may be compiled into an intermediate representation (such as byte code) or into machine code, for example to enable the compiled code to be executed in place of the original traditionally interpreted code, which typically affords performance advantages. FIGS. 1A and 1B are block diagrams illustrating prior art systems for compiling source code, including source code in a traditionally interpreted programming language, such as JavaScript. In the example shown in FIG. 1A, source code 102 is compiled by a compiler 104 to generate machine code 106. In the example shown in FIG. 1B, source code 122 is processed by an initial byte code generator 124 to generate an initial intermediate representation of the source code. Subsequently, a compiler 126 is used to perform optimization processing on the byte code and to generate machine code 128 based on the optimized byte code.
Traditionally, when compiling code written in a traditionally interpreted or other language that does not use the constant pool approach, constants in the source code are identified and code to store such constants in a constant pool is generated in connection with initial code generation, i.e., the first stage of code generation based directly on the original source code, such as the initial byte code generated by byte code generator 124 in the example shown in FIG. 1B. Optimizations traditionally have been performed on such initially generated code prior to final, optimized machine code being generated. FIG. 2 is a flow diagram illustrating a prior art process for compiling source code. In the example shown in FIG. 2, source code (202) is analyzed to create a constant pool (204), e.g., in connection with initial code generation based on the source code. Subsequent to initial code generation and constant pool creation, optimizations are performed and optimized machine code generated (206).